//
//  YTCollectionHeaderView.m
//  qiyunapp
//
//  Created by qiyun on 2018/7/12.
//  Copyright © 2018年 qiyun. All rights reserved.
//

#import "YTCollectionHeaderView.h"

@implementation YTCollectionHeaderView
+ (NSString *)headerViewIdentifier{
    static NSString *footerIdentifier = @"footerViewIdentifier";
    return footerIdentifier;
}
+ (instancetype)headerViewWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath
{
    //从缓存池中寻找底部视图对象，如果没有，该方法自动调用alloc/initWithFrame创建一个新的底部视图返回
    YTCollectionHeaderView *headerView =
    [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:[YTCollectionHeaderView headerViewIdentifier] forIndexPath:indexPath];
    return headerView;
}
/* 注册了底部视图后，当缓存池中没有底部视图的对象时候，自动调用alloc/initWithFrame创建 */
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(7, 12, 100, 13)];
        textLabel.numberOfLines = 0;
        textLabel.textAlignment = NSTextAlignmentCenter;
        //添加到父控件
        [self addSubview:textLabel];
        self.textLabel = textLabel;
      }
    return self;
    
}
@end
